package com.flida.echart.basic.service;

import com.flida.echart.basic.api.service.GateSystemService;
import com.flida.echart.basic.api.system.entity.SysConfigEntity;
import com.flida.echart.basic.system.service.SysConfigService;
import com.flida.echart.basic.system.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by yzc on 2016/12/18.
 */
@Service("gateSystemService")
public class GateSystemServiceImpl implements GateSystemService {

    @Autowired
    public SysConfigService sysConfigService;

    /**
     * 保存配置信息
     *
     * @param config
     */
    public void saveConfig(SysConfigEntity config) {
        sysConfigService.save(config);
    }

    /**
     * 更新配置信息
     *
     * @param config
     */
    public void updateConfig(SysConfigEntity config) {
        sysConfigService.update(config);
    }

    /**
     * 根据key，更新value
     *
     * @param key
     * @param value
     */
    public void updateValueByKeyConfig(String key, String value) {
        sysConfigService.updateValueByKey(key, value);
    }

    /**
     * 删除配置信息
     *
     * @param ids
     */
    public void deleteBatchConfig(Long[] ids) {
        sysConfigService.deleteBatch(ids);
    }

    /**
     * 获取List列表
     *
     * @param map
     */
    public List<SysConfigEntity> queryListConfig(Map<String, Object> map) {
        return sysConfigService.queryList(map);
    }

    /**
     * 获取总记录数
     *
     * @param map
     */
    public int queryTotalConfig(Map<String, Object> map) {
        return sysConfigService.queryTotal(map);
    }

    public SysConfigEntity queryObjectConfig(Long id) {
        return sysConfigService.queryObject(id);
    }

    /**
     * 根据key，获取配置的value值
     *
     * @param key          key
     * @param defaultValue 缺省值
     */
    public String getValueConfig(String key, String defaultValue) {
        return sysConfigService.getValue(key, defaultValue);
    }

    /**
     * 根据key，获取value的Object对象
     *
     * @param key   key
     * @param clazz Object对象
     */
    public <T> T getConfigObject(String key, Class<T> clazz) throws Exception {
        return sysConfigService.getConfigObject(key, clazz);
    }
}
